<?
$numberUndecidedDecisions = getNumberUndecidedKPPStatusReviews($loggedInTeam->coachName);
?>

<? if (Admin::isAuthentic($loggedInTeam->coachName)) {?>
	<table>
		<tr><td><b>goblues101</b></td><td><?echo getNumberUndecidedKPPStatusReviews("goblues101")?></td></tr>
		<tr><td><b>Stooper</b></td><td><?echo getNumberUndecidedKPPStatusReviews("Stooper")?></td></tr>
    	<tr><td><b>JB0016</b></td><td><?echo getNumberUndecidedKPPStatusReviews("JB0016")?></td></tr>
    	<tr><td><b>scrote</b></td><td><?echo getNumberUndecidedKPPStatusReviews("scrote")?></td></tr>
    	<tr><td><b>mallia</b></td><td><?echo getNumberUndecidedKPPStatusReviews("mallia")?></td></tr>
    	</table>
<?}?>
<? if ($numberUndecidedDecisions > 0) {?>			
	<div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;"> 
		<p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
		<strong>You have <?echo $numberUndecidedDecisions?> outstanding decisions.</strong></p>
	</div>
<?}?>
<?
$numResults = getNumberKPPStatusReviews();
$maxPerPage = $userSettings->getSettingValue(SettingType::KPPStatusPerPage);
$reviews = getKPPStatusReviews($reviewPage, $maxPerPage);
$count3 = count($reviews);
$count4 = $numResults/$maxPerPage;
if ($numResults%$maxPerPage > 0) {
	$count4++;
}
?>
<br>
<br>
<br>
<b>Pages:</b>&nbsp;<?for ($k = 1; $k <= $count4; $k++) {
	if ($k > 1) {
		echo " | ";
	}
?>
	<a href="javascript: document.pageNumberForm.reviewPage.value=<?echo $k?>;submitPageNumberForm('#tabs-KPPStatusReview')"><?echo $k?></a>
<?}?>
<table width="100%">
	<tr><td width="60%" valign="top">
		<table align="center" width="100%" border="2" cellpadding="10">
			<tr>
				<td width="25%"><b>Player</b></td>
				<td width="20%"><b>Description</b></td>
				<td width="5%"><b>GB</b></td>
				<td width="5%"><b>mallia</b></td>
				<td width="5%"><b>scrote</b></td>
				<td width="5%"><b>JB0016</b></td>
				<td width="5%"><b>Stooper</b></td>
				<!-- td width="5%"><b>Maso</b></td -->
				<td width="5%"><b>Overall</b></td>
				<td width="5%"><b>Comments</b></td>
			</tr>
			<?
			for ($i = 0; $i < $count3; $i++) {
				$playerDesc = getPlayerDisplayForPlayer($reviews[$i]->player);
			?>
			<tr>
				<td><?echo $playerDesc?></td>
				<td><?echo $reviews[$i]->description?></td>
				<td><?echo getImage($reviews[$i]->id, $reviews[$i]->getDecision("goblues101"), "goblues101", $loggedInTeam->coachName, $playerDesc, $reviews[$i]->description, $reviews[$i]->getNumberDecided(), $reviewPage)?></td>
				<td><?echo getImage($reviews[$i]->id, $reviews[$i]->getDecision("mallia"), "mallia", $loggedInTeam->coachName, $playerDesc, $reviews[$i]->description, $reviews[$i]->getNumberDecided(), $reviewPage)?></td>
				<td><?echo getImage($reviews[$i]->id, $reviews[$i]->getDecision("scrote"), "scrote", $loggedInTeam->coachName, $playerDesc, $reviews[$i]->description, $reviews[$i]->getNumberDecided(), $reviewPage)?></td>
				<td><?echo getImage($reviews[$i]->id, $reviews[$i]->getDecision("JB0016"), "JB0016", $loggedInTeam->coachName, $playerDesc, $reviews[$i]->description, $reviews[$i]->getNumberDecided(), $reviewPage)?></td>
				<td><?echo getImage($reviews[$i]->id, $reviews[$i]->getDecision("Stooper"), "Stooper", $loggedInTeam->coachName, $playerDesc, $reviews[$i]->description, $reviews[$i]->getNumberDecided(), $reviewPage)?></td>
				<!-- td><?echo getImage($reviews[$i]->id, $reviews[$i]->getDecision("Maso"), "Maso", $loggedInTeam->coachName, $playerDesc, $reviews[$i]->description, $reviews[$i]->getNumberDecided(), $reviewPage)?></td -->
				<td><?echo getImage($reviews[$i]->id, $reviews[$i]->getOverallDecision(), null, $loggedInTeam->coachName, $playerDesc, $reviews[$i]->description, $reviews[$i]->getNumberDecided(), $reviewPage)?></td>
				<td id="comments<?echo $reviews[$i]->id?>"><input type="button" value="Show" style="width: 70px" onclick="populateComments(<?echo $reviews[$i]->id ?>)"><br><input type="button" value="Add" style="width: 70px" onclick="addComment(<?echo $reviews[$i]->id?>, '<?echo $loggedInTeam->coachName?>', '<?echo $playerDesc . ' ' . $reviews[$i]->description?>', <?echo $reviewPage?>)"></td>
			</tr>
			<?}?>
		</table>
	</td>
	<td width="40%" valign='top'>
		<div id="comments">
		</div>
	</td>
	</tr>
</table>
	
<?
function getImage($id, $decision, $boardMember, $loggedInUser, $player, $description, $numberDecided, $page) {
	$result = "";
	if ($decision == "YES") {
		$result = "<img src='../../../images/tick.jpg'>";
	}
	else if ($decision == "NO") { 
		$result = "<img src='../../../images/cross.jpg'>";
	}
	else if ($decision == "HUNG") { 
		$result = "HUNG";
	}
	else {
		$result = "<b>ND</b>";
	}
	if ($boardMember == $loggedInUser && $numberDecided < 5) {
		$result .= "<br><input type='button' value='Decide' style='width: 70px' onclick=\"openMakeDecision($id, '" . $player . " " . $description . "', '$boardMember', $page)\">";
	}
	
	return $result;
}
?>
<script>
	var description = "";
	function openMakeDecision(id, reviewDesc, boardMember, page) {
		window.open('../kppStatusReview/makeDecision.php?page=' + page + '&id=' + id + '&boardMember=' + boardMember + '&desc=' + reviewDesc,'','width=400,height=300')
	}

	function addComment(id, boardMember, reviewDesc, page) {
		window.open('../kppStatusReview/makeDecision.php?page=' + page + '&justComment=true&id=' + id + '&boardMember=' + boardMember + '&desc=' + reviewDesc,'','width=400,height=300')
	}
</script>

<script>
function ReviewComment(id, boardMember, comment) {
	this.id = id;
	this.boardMember = boardMember;
	this.comment = comment;
}
var lastId = -1;
function populateComments(id) {
	var result = "<table border=2 cellpadding=10 width='100%' valign='top'><tr><td width='30%'><b>Board Member</b></td><td width='70%'><b>Comment</b></td></tr>";
	for (i=0; i<comments.length; i++) {
		if (comments[i].id == id) {
			result += "<tr><td>" + comments[i].boardMember + "</td><td>" + comments[i].comment + "</td></tr>";
		}
	}
	result += "</table>";
	
	document.getElementById('comments').innerHTML = result;
	document.getElementById('comments' + id).style.backgroundColor = "#3399FF";
	if (lastId != -1) {
		document.getElementById('comments' + lastId).style.backgroundColor = "white";
	}
	lastId = id;
}

var comments = new Array();
<?
echo "var firstReviewId = " . $reviews[0]->id . ";\n";
$count6 = 0;
for ($i = 0; $i < $count3; $i++) {
	$count2 = count($reviews[$i]->comments);
	for ($j = 0; $j < $count2; $j++) {
	?>
		comments[<?echo $count6?>] = new ReviewComment(<?echo $reviews[$i]->id?>, "<?echo $reviews[$i]->comments[$j]->boardMember?>", "<?echo $reviews[$i]->comments[$j]->comment?>");
<?
		$count6++;
	}
}
?>
populateComments(firstReviewId);
</script>
